--[[

    Copyright (c) 2011-2020 baby-bus.com

    TODO:   SpriteName
    Author: DemonYao
    Date:   2020.09.21
 
    http://www.babybus.com/ 

]] 




--------------------------
-- 引入命名空间
--------------------------
-- local BaseLayer = import("app.common.layer.BaseLayer")




--[[
    类
--]]


local M = classSprite("dragonBone")
local dbFactory = dragonBones.CCFactory



--------------------------
-- 构造函数
--------------------------

function M:ctor(params)
    -- [超类调用]
    M.super.ctor(self, params)
    -- [本类调用]
    self.dragonBonesDataFile  = params.dragonBonesDataFile      -- 骨骼文件
    self.dragonBonesTexFile   = params.dragonBonesTexFile       -- 骨骼文件
    self.armatureName         = params.armatureName             -- 骨骼名称
    self.animName             = params.animName                 -- 初始骨骼动作名称（选填）
end

--------------------------
-- 渲染
--------------------------

function M:onRender()
    M.super.onRender(self)
    -- [本类调用]
    -- 加载节点
    self:createArmature()
end

-- 加载节点
function M:loadDisplay()
    -- 
end

-- 加载渲染以外的其他操作
function M:onEnterTransitionFinish()
    --触控 

    self:bindTouchLocate()
    tool:loadHelpRect({
		node = self,
		pos = cc.p(0, 0),
		size = cc.size(self:cw(), self:ch()),
		anchorPoint = cc.p(0, 0)
	}):opacity(200):z(-1)
end

-- 创建骨骼
function M:createArmature()
	dragonBones.CCFactory:loadDragonBonesData(self.dragonBonesDataFile, "test")
	dragonBones.CCFactory:loadTextureAtlasData(self.dragonBonesTexFile, "test")
    local armatureDisplay = dragonBones.CCFactory:buildArmatureDisplay(self.armatureName)
    CCNodeExtend.extend(armatureDisplay)
    -- 设置节点大小
    self:setContentSize(cc.size(armatureDisplay:cw(), armatureDisplay:ch()))

    armatureDisplay:anchor(cc.p(0.5, 0.5))
    local size = armatureDisplay:getContentSize()
    local anchor = armatureDisplay:getAnchorPoint()
    
    armatureDisplay:to(self):p(size.width * anchor.x, size.height * anchor.y)

    if self.animName then
        armatureDisplay:getAnimation():play(self.animName)
    end
end


--------------------------
-- 触控
-------------------------- 

function M:onTouchBegan(x, y, touches)
    --  触控有效
    return SIGN_TOUCH_BEGAN_SWALLOWS
end

function M:onTouchMoved(x, y, touches)
    --  
end

function M:onTouchEnded(x, y, touches)
    --  
end



--------------------------
-- 功能函数
--------------------------




--------------------------
-- 属性
--------------------------




--------------------------
-- 父类重写
--------------------------




----------------------------------------------------
-- 析构
--------------------------

function M:onDestructor()
    -- [超类调用]
M.super.onDestructor(self)
    -- [本类调用]

end








return M






